package com.shfl.Controller;

import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.ResourceBundle;

import com.Main;
import com.shfl.app.One;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;

public class LoginController implements Initializable {

	@FXML
	private Button login;

	@FXML
	private TextField passWord;

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void initialize(URL location, ResourceBundle resources) {
		this.login.setOnAction(event -> {
			 SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
			 System.out.println(formatDateTime(myFormat.format(new Date())).toString());
			 String password = this.passWord.getText();
			 String passWord1 = formatDateTime(myFormat.format(new Date())).toString();
			if(password.equals(passWord1)){
				try {
					changeWindow();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
	}

	public void changeWindow() throws Exception {
		Main login = new Main();
		login.stop();
		One one = new One();
		one.showWindow();
	}
	
	public static void main(String[] args) {
		 SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
		System.out.println(formatDateTime(myFormat.format(new Date())).toString());
	}
	
	public static Long formatDateTime(String strDateTime) {
		strDateTime = strDateTime+" 00:00:00";
		if(strDateTime.endsWith("1")){
			strDateTime = strDateTime+" 11:11:11";
		}
		if(strDateTime.endsWith("2")){
			strDateTime = strDateTime+" 22:22:22";
		}
		if(strDateTime.endsWith("3")){
			strDateTime = strDateTime+" 23:33:33";
		}
		
        if (strDateTime == null || "".equals(strDateTime)) {
            return null;
        } else {
            SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			try {
				Date myDate = myFormat.parse(strDateTime.trim());
				return myDate.getTime();
			} catch (ParseException e) {
				e.printStackTrace();
			}
           return null;
        }
    }

}
